 <?php 
  try {  	
  $form = $_POST['form'];
  $DistrictUid = $form['DISTRICT_UID'];
  $DistrictstateId = $form['DISTRICTSTATE_ID'];
  $Districtname = $form['DISTRICTNAME'];
  $Districtaddress1 = $form['DISTRICTADDRESS1'];
  $Districtaddress2 = $form['DISTRICTADDRESS2'];
  $Districtcity = $form['DISTRICTCITY'];
  $Districtcounty = $form['DISTRICTCOUNTY'];
  $Districtzipcode = $form['DISTRICTZIPCODE'];
  $Districtphone = $form['DISTRICTPHONE'];
  $Districtfax = $form['DISTRICTFAX'];
  $Districtwebsite = $form['DISTRICTWEBSITE'];
  $Sersdistrictcode = $form['SERSDISTRICTCODE'];
  $Strsdistrictcode = $form['STRSDISTRICTCODE'];
  $Stateidnumber = $form['STATEIDNUMBER'];
  $Federalidnumber = $form['FEDERALIDNUMBER'];
  $Odjpsnumber = $form['ODJPSNUMBER'];

  require_once ( PATH_PLUGINS . 'hr' . PATH_SEP . 'class.hr.php');
  $pluginObj = new hrClass ();

  require_once ( "classes/model/HrDistricts.php" );

     //if exists the row in the database propel will update it, otherwise will insert.
     $tr = HrDistrictsPeer::retrieveByPK( $DistrictUid );
     if ( ! ( is_object ( $tr ) &&  get_class ($tr) == 'HrDistricts' ) ) {
       $tr = new HrDistricts();
     }
     $tr->setDistrictUid( $DistrictUid );
     $tr->setDistrictstateId( $DistrictstateId );
     $tr->setDistrictname( $Districtname );
     $tr->setDistrictaddress1( $Districtaddress1 );
     $tr->setDistrictaddress2( $Districtaddress2 );
     $tr->setDistrictcity( $Districtcity );
     $tr->setDistrictcounty( $Districtcounty );
     $tr->setDistrictzipcode( $Districtzipcode );
     $tr->setDistrictphone( $Districtphone );
     $tr->setDistrictfax( $Districtfax );
     $tr->setDistrictwebsite( $Districtwebsite );
     $tr->setSersdistrictcode( $Sersdistrictcode );
     $tr->setStrsdistrictcode( $Strsdistrictcode );
     $tr->setStateidnumber( $Stateidnumber );
     $tr->setFederalidnumber( $Federalidnumber );
     $tr->setOdjpsnumber( $Odjpsnumber );

     if ($tr->validate() ) {
       // we save it, since we get no validation errors, or do whatever else you like.
       $res = $tr->save();
     }
     else {
       // Something went wrong. We can now get the validationFailures and handle them.
       $msg = '';
       $validationFailuresArray = $tr->getValidationFailures();
       foreach($validationFailuresArray as $objValidationFailure) {
         $msg .= $objValidationFailure->getMessage() . "<br/>";
       }
       //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
     }
    //return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');

    //to do: uniform  coderror structures for all classes

  //if ( $res['codError'] < 0 ) {
  //  G::SendMessageText ( $res['message'] , 'error' );  
  //}
  G::Header('location: hrDistrictsList');   
  
  }
  catch ( Exception $e ) {
    $G_PUBLISH = new Publisher;
    $aMessage['MESSAGE'] = $e->getMessage();
    $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
    G::RenderPage( 'publish', 'blank' );
  }      
   